package com.functest.jpwise

import com.functest.jpwise.core.ParameterValue
import com.functest.jpwise.core.TestParameter

/**
 * @author: DavydovMD
 * Date: 17.06.13
 * Time: 19:18
 */
class SmartParameter extends TestParameter {
    private List<Closure<Boolean>> compatibilityClosures;

    /**
     *  Constructor.
     * @param theName parameter name (for reporting only)
     * @param parameterValues list of parameter value objects
     */
    SmartParameter(String theName, List<ParameterValue> parameterValues, List<Closure<Boolean>> compatibilityClosures = [{ v1, v2 -> true }]) {
        super(theName, parameterValues)
        this.compatibilityClosures = compatibilityClosures
    }

    @Override
    boolean areCompatible(ParameterValue thisValue, ParameterValue thatValue) {
        for (Closure<Boolean> compatibilityClosure : compatibilityClosures) {
            if (compatibilityClosure(thisValue, thatValue)) return true;
        }
        false;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder('SmartParameter{');
        sb.append(this.values);
        sb.append(';dependencies(').append(compatibilityClosures.size()).append(')');
        sb.append('}');
         sb.toString();
    }
}
